%% On the Optimal Design of Transfers and Income-Tax Progressivity
% Illustration of new income tax function

clear; clc; close all;
addpath('../../Matlab_Figure_Files');

%% Income tax function: comparison to HSV

% Parameters
theta_low = 0.10;       % low progressivity
theta_bench = 0.0772*2; % benchmark progressivity
theta_high = 0.24;      % high progressivity
lambda_low = 0.20;      % low level
lambda_bench = 0.2469;  % benchmark level
lambda_high = 0.30;     % high level

% Grid
y_min = 0.01;           % minimum of income grid
y_max = 5;              % maximum of income grid
y_n = 1000;             % number points on income grid
y_grid = linspace(y_min,y_max,y_n); % income grid
ymean = 1;              % mean income

% Functional form
tax_rate_bench = exp(log(lambda_bench)*(y_grid./ymean).^(-theta_bench));     % benchmark theta, benchmark lambda
marg_rate_bench = exp(log(lambda_bench)*(y_grid./ymean).^(-theta_bench)).*(1-theta_bench*log(lambda_bench)*((y_grid./ymean).^(-theta_bench)));    % marginal rate
tax_rate_lowtheta = exp(log(lambda_bench)*(y_grid./ymean).^(-theta_low));    % low theta, benchmark lambda
tax_rate_hightheta = exp(log(lambda_bench)*(y_grid./ymean).^(-theta_high));  % high theta, benchmark lambda
tax_rate_lowlambda = exp(log(lambda_low)*(y_grid./ymean).^(-theta_bench));   % benchmark theta, low lambda
tax_rate_highlambda = exp(log(lambda_high)*(y_grid./ymean).^(-theta_bench)); % benchmark theta, high lambda

% Corresponding HSV parameters
lambda_HSV = 1-lambda_bench; 
tau_HSV = theta_bench/2;

% Functional form HSV
tax_rate_hsv  = 1-lambda_HSV*(y_grid./ymean).^(-tau_HSV);
marg_rate_hsv = 1-(1-tau_HSV)*lambda_HSV*((y_grid./ymean).^(-tau_HSV)); 

% Figure for paper
fig = figure(101);
subplot(1,2,1)
plot(y_grid,tax_rate_bench,y_grid,tax_rate_hsv,'--','linewidth',2)
ylim([0 .5])
xlim([0 y_grid(end)])
ylabel('Average tax rate','Interpreter','LaTex','Fontsize',12)
xlabel('$y_\ell$','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
leg = legend('New tax function','Log-linear tax function');
set(leg,'Interpreter','LaTex','Location','NorthWest','Fontsize',12)  
legend boxoff
subplot(1,2,2)
plot(y_grid,marg_rate_bench,y_grid,marg_rate_hsv,'--','linewidth',2)
ylim([0 .5])
xlim([0 y_grid(end)])
ylabel('Marginal tax rate','Interpreter','LaTex','Fontsize',12)
xlabel('$y_\ell$','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
run graph_extended.m
saveas(gcf,'fgnv_hsv.pdf')

fig = figure(102);
subplot(1,2,1)
plot(y_grid,tax_rate_bench,'-','Color',[0 0 0],'linewidth',2); hold on
plot(y_grid,tax_rate_hsv,'--','Color',[0.7 0.7 0.7],'linewidth',2); hold off
ylim([0 .5])
xlim([0 y_grid(end)])
ylabel('Average tax rate','Interpreter','LaTex','Fontsize',12)
xlabel('$y_\ell$','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
leg = legend('New tax function','Log-linear tax function');
set(leg,'Interpreter','LaTex','Location','NorthWest','Fontsize',12)  
legend boxoff
subplot(1,2,2)
plot(y_grid,marg_rate_bench,'-','Color',[0 0 0],'linewidth',2); hold on
plot(y_grid,marg_rate_hsv,'--','Color',[0.7 0.7 0.7],'linewidth',2); hold off
ylim([0 .5])
xlim([0 y_grid(end)])
ylabel('Marginal tax rate','Interpreter','LaTex','Fontsize',12)
xlabel('$y_\ell$','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
run graph_extended.m
saveas(gcf,'fgnv_hsv_bw.pdf')
saveas(gcf,'fgnv_hsv_bw','epsc')

%% Income tax function and transfer function

% Transfer parameters
m_bench = 0.0885;     % benchmark level parameter
chi_bench = 4.2199;   % benchmark phase-out parameter
m_low = 0.05;         % lower level parameter
chi_low = 2;          % lower phase-out parameter

% Benchmark transfer
num = 2*m_bench*ymean*exp(-chi_bench*(y_grid/ymean));
den = 1 + exp(-chi_bench*(y_grid/ymean));
t1  = num./den;

% Lower level
num = 2*m_low*ymean*exp(-chi_bench*(y_grid/ymean));
den = 1 + exp(-chi_bench*(y_grid/ymean));
t2  = num./den;

% Slower phase-out
num = 2*m_bench*ymean*exp(-chi_low*(y_grid/ymean));
den = 1 + exp(-chi_low*(y_grid/ymean));
t3  = num./den;

% Figure for paper
fig = figure(103);
subplot(1,2,1)
plot(y_grid,tax_rate_bench,'-',y_grid,tax_rate_hightheta,'--',y_grid,tax_rate_highlambda,':','linewidth',2)
ylim([0 .4])
xlim([0 5])
ylabel('Average tax rate','Interpreter','LaTex','Fontsize',12)
xlabel('$y_\ell$','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
leg = legend('Calibration','Higher progressivity','Higher level');
set(leg,'Interpreter','LaTex','Location','SouthEast','Fontsize',12)         
legend boxoff
subplot(1,2,2)
plot(y_grid,t1,y_grid,t2,'--',y_grid,t3,':',y_grid,0*y_grid,':k','LineWidth',2)
leg = legend('Calibration','Lower level','Slower phase-out');%,'$\lambda=0.24$');
set(leg,'Interpreter','LaTex','Location','NorthEast','Fontsize',12)                
legend boxoff
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
ylim([-0.01 0.10])
xlim([0 5])
ylabel('Transfer over mean income','Interpreter','LaTex','Fontsize',12)
xlabel('$y$ ','Interpreter','LaTex','Fontsize',12)
run graph_extended.m
saveas(gcf,'NewFunctions.pdf')

fig = figure(104);
subplot(1,2,1)
plot(y_grid,tax_rate_bench,'-','Color',[0 0 0],'linewidth',2); hold on
plot(y_grid,tax_rate_hightheta,'--','Color',[0.4 0.4 0.4],'linewidth',2); hold on
plot(y_grid,tax_rate_highlambda,':','Color',[0.7 0.7 0.7],'linewidth',2); hold off
ylim([0 .4])
xlim([0 5])
ylabel('Average tax rate','Interpreter','LaTex','Fontsize',12)
xlabel('$y_\ell$','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
leg = legend('Calibration','Higher progressivity','Higher level');
set(leg,'Interpreter','LaTex','Location','SouthEast','Fontsize',12)         
legend boxoff
subplot(1,2,2)
plot(y_grid,t1,'-','Color',[0 0 0],'linewidth',2); hold on
plot(y_grid,t2,'--','Color',[0.4 0.4 0.4],'linewidth',2); hold on
plot(y_grid,t3,':','Color',[0.7 0.7 0.7],'linewidth',2); hold on
plot(y_grid,0*y_grid,':k','LineWidth',2); hold off
leg = legend('Calibration','Lower level','Slower phase-out');%,'$\lambda=0.24$');
set(leg,'Interpreter','LaTex','Location','NorthEast','Fontsize',12)                
legend boxoff
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
ylim([-0.01 0.10])
xlim([0 5])
ylabel('Transfer over mean income','Interpreter','LaTex','Fontsize',12)
xlabel('$y$ ','Interpreter','LaTex','Fontsize',12)
run graph_extended.m
saveas(gcf,'NewFunctions_bw.pdf')
saveas(gcf,'NewFunctions_bw','epsc')
